/** 操作成功或操作失败 弹框提示**/
function Notify(status,info){
	this.status=status;
	this.info=info;
	this.init()
}
Notify.prototype.init = function(){
	var type = this.status;
	if(type == 'success'){
		$.smallBox({
			title: "修改成功",
			content: "<i class='fa fa-clock-o'></i> <i>"+this.info+"</i>",
			color: "#659265",
			iconSmall: "fa fa-check fa-2x fadeInRight animated",
			timeout: 4000
		});
	}else if(type == 'fail'){
		$.smallBox({
			title: "操作失败",
			content: "<i class='fa fa-clock-o'></i> <i>"+this.info+"</i>",
			color: "#a90329",
			iconSmall: "fa fa-exclamation-triangle fa-2x fadeInRight animated",
			timeout: 4000
		});
	}else if(type == 'info'){
		$.smallBox({
			title: "没有权限",
			content: "<i class='fa fa-clock-o'></i> <i>"+this.info+"</i>",
			color: "#c79121",
			iconSmall: "fa fa-exclamation-triangle fa-2x fadeInRight animated",
			timeout: 4000
		});
	}
};

//获取当前时间
function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
			+ " " + date.getHours() + seperator2 + date.getMinutes()
			+ seperator2 + date.getSeconds();
	return currentdate;
}


//js获取日期：前天、昨天、今天、明天、后天
function GetDateStr(AddDayCount) { 
	var dd = new Date(); 
	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期 
	var y = dd.getFullYear(); 
	var m = dd.getMonth()+1;//获取当前月份的日期 
	var d = dd.getDate(); 
	return y+"-"+m+"-"+d; 
}
// "前天："+GetDateStr(-2) 
// "昨天："+GetDateStr(-1) 
// "今天："+GetDateStr(0) 
// "明天："+GetDateStr(1) 
// "后天："+GetDateStr(2) 
// "大后天："+GetDateStr(3) 

//获取业务操作码busicode:
function getBusicode(){
	var date = new Date();
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var Num=""; //六位随机数
	for(var i=0;i<6;i++) 
	{ 
		Num+=Math.floor(Math.random()*10); 
	} 
	var busicode = date.getFullYear() +""+ month +""+ strDate +""
			+ date.getHours() +""+ date.getMinutes() +""+ date.getSeconds()
			+ Num;
	
	return busicode;
}

//云仓系统  跳转至  油库系统
function JumpInTo($http,param){
	//新用户
	// var param = {userid: "yk_xhy", roleid: "1120", rolename: "万企汇云仓_模型_管理角色", code: "YC_HB_YKCS"};

	if(param.userid!="" && param.roleid!="" && param.rolename!="" && param.code!=""){
		$http.post(baseurls+"/userlogin",{id:'wancloud@qq.com',pass:'111111'}).then(function(response){
			//以管理员方式登录  来创建角色和用户
			//获得仓库id
			$http.get(baseurls+"/detail/project?code=="+param.code).then(function(res){
				if(res.data.ret == 1){//仓库存在
					var new_code_id = res.data.info.id;
					add_role(param.roleid,param.rolename,new_code_id)
				}
			})

		})
	}
    
    //添加角色方法
    function add_role(roleid,rolename,code){
        $http.get(baseurls+"/detail/role?id=="+roleid).then(function(res){
            // console.log(res.data)
            if(res.data.ret == -1){//没有这个角色->创建该仓库的角色
                var new_role = {
                    id: roleid,
                    name: rolename,
                    des: rolename,
                    projectid: code,
                    power: JSON.stringify([{"projectid":code,"power":6}]),
                    fid: 'admin'
                }
                // console.log(new_role)
                //添加角色
                $http.post(baseurls+"/data/role",new_role).then(function(res2){
                    if(res2.data.ret == 1){
                        console.log("new role create ok");
                        add_user(param.userid,roleid)
                    }
                })
            }else{//角色存在->添加用户
                add_user(param.userid,roleid)
            }
        })
    }
    //添加用户方法
    function add_user(userid,roleid){
        $http.get(baseurls+"/detail/user?id=="+userid).then(function(res){
            // console.log(res.data)
            if(res.data.ret == -1){//没有这个用户->创建该用户
                var new_user = {
                    id: param.userid,
                    name: param.userid,
                    pass: '96e79218965eb72c92a549dd5a330112',
                    clientname: '万企汇云仓',
                    roleid: param.roleid,
                    fid: 'admin',
                    timefrom: getNowFormatDate()
                }
                // console.log(new_user)
                //添加用户
                $http.post(baseurls+"/data/user",new_user).then(function(res2){
                    if(res2.data.ret == 1){
                        console.log("new user create ok");
                    }
                })
            }else{
            }
        })
    }
}